<template>
  <div class="box">
    <div class="title">
      <div class="title_fan">首页</div>
      <!-- 搜索 -->
      <div class="title_input">
        <div class="el-icon-search"></div>
        <input type="text" placeholder="搜索">
        <div class="title_sys" @click="$router.push({path:'/listscan'})">
          <img src="../../../../assets/static/home/scan.png" alt="扫码图标">
        </div>
      </div>
      <!-- 钱包 积分 card -->
      <div class="title_card">
        <div @click="$router.push({path:'/listpayment'})">
          <div>钱包</div>
          <div>
            <img src="../../../../assets/static/home/329.png" alt="">
            <div>
              <span>{{ balance }}</span>
            </div>
          </div>
        </div>
        <div class="title_card_backColor"></div>
        <div @click="goto('membership')">
          <div>积分</div>
          <div>
            <img src="../../../../assets/static/home/330.png" alt="">
            <div>
              <span>{{ score }}</span>
            </div>
          </div>
        </div>
      </div>
      <!-- 商品 -->
      <div class="goods">
        <!-- card -->
        <div class="goods_list_card">
          <div>
            <img src="../../../../assets/static/home/p2.png" alt="">
            <div>Shop</div>
          </div>
          <div @click="$router.push({path:'/listpayQrcode',query:{type:'pay'}})">
            <img src="../../../../assets/static/home/p1.png" alt="">
            <div>Payment</div>
          </div>
          <div @click="$router.push({path:'/listscanOpen'})">
            <img src="../../../../assets/static/home/p3.png" alt="">
            <div>Smart kiosk</div>
          </div>
        </div>
        <div v-for="item in 2" :key="item">
          <div class="goods_title_flex">
            <div class="card_title">
              <img src="../../../../assets/static/recharge/q4.png" alt=""/>
              <div>What's new this week</div>
            </div>
            <img src="../../../../assets/static/home/y2.png" alt="">
          </div>
          <div v-show="item===1" class="goods_come">
            <div v-for="info in datalist"
                 v-show="info.article_category==='2'"
                 @click="gotoDetail(info)"
                 :key="info.ROW_NUMBER">
              <el-image class="elImage row-wrapper" fit="fill" :src="info.image">
                <div slot="error" class="image-slot">
                  <i class="el-icon-picture-outline font-errImage"></i>
                </div>
              </el-image>
              <!--              <img :src="info.image" alt="">-->
              <div class="goods-name">
                <span>{{ info.title }}</span>
              </div>
            </div>
          </div>
          <div v-show="item===2" class="goods_come">
            <div v-for="info in datalist"
                 v-show="info.article_category!=='2'"
                 @click="gotoDetail(info)"
                 :key="info.ROW_NUMBER">
              <img :src="info.image" alt="">
              <div class="goods-name">
                <span>{{ info.title }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {index} from '@/api/merbership/home'
import {myInfo} from '@/api/merbership/my'
import {setUid} from '@/utils/tokenTools'
import '@/styles/flax.css'

export default {
  data() {
    return {
      datalist: [{}],
      balance: '',
      score: ''
    }
  },
  methods: {
    /**
     * 页面跳转
     * @param index
     */
    goto(index) {
      switch (index) {
        case 'home':
          this.$router.push({path: '/listhome'})
          break
        case 'active':
          this.$router.push({path: 'listhome'})
          break
        case 'pay':
          this.$router.push({path: 'listhome'})
          break
        case 'message':
          this.$router.push({path: 'listhome'})
          break
        case 'my':
          this.$router.push({path: '/listMy'})
          break
        case 'membership':
          this.$router.push({path: '/listmembership'})
          break
        default:
          break
      }
    },
    /**
     * 跳转到文章细节
     * @param info
     */
    gotoDetail(info) {
      this.$router.push({path: '/listnewsDetail', query: {id: info.id}})
    },
    // ----------------- axios --------------------
    /**
     * 获取个人信息
     */
    myInfo() {
      const pd = {}
      myInfo(pd)
        .then(res => {
          setUid(res.data.data.id)
        })
    },
    /**
     * 首页数据
     */
    index() {
      const pd = {
        page: 1,
        limit: 10
      }
      index(pd)
        .then(res => {
          this.datalist = res.data.data.list
          this.balance = res.data.data.balance
          this.score = res.data.data.score
        })
    }
  },
  mounted() {
    this.index()
    this.myInfo()
  }
}
</script>

<style lang="scss" scoped>
.font-errImage {
  font-size: 45px;
}

.elImage {
  justify-content: center;
  width: 100%;
  height: 120px;
}

/* 标题 */
.title {
  background-color: #7AC91B;

  .title_fan {
    color: #fff;
    font-size: 18px;
    padding: 15px;
    text-align: center;
  }

  // input
  .title_input {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 15px;
    padding: 5px 10px;
    border-radius: 6px;
    background-color: #fff;
    box-shadow: 0 0 10px #ccc;

    .el-icon-search {
      font-size: 16px;
      font-weight: bold;
      color: #67C41D;
    }

    input {
      width: 80%;
      border: none;
      outline: none;
      color: #67C41D;
    }

    input::-webkit-input-placeholder {
      color: #67C41D;
    }

    .title_sys {
      width: 30px;
      padding-top: 4px;
      text-align: center;
      border-radius: 6px;
      background-image: linear-gradient(to right, #7AC91B, #5FBE00);
      vertical-align: top;

      img {
        width: 13px;
        height: 13px;
      }
    }
  }

  // 钱包
  .title_card {
    margin: 15px;
    background-color: #fff;
    padding: 40px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 8px;

    > div {
      width: 50%;
      text-align: center;

      > div:nth-child(1) {
        font-size: 11px;
        color: #666;
      }

      > div:nth-child(2) {
        margin-top: 10px;
        font-size: 21px;
        font-weight: bold;
        display: flex;
        align-items: center;
        justify-content: center;

        img {
          width: 21px;
          margin-right: 6.5px;
        }
      }
    }

    .title_card_backColor {
      width: 1px;
      height: 32px;
      background-color: #D4D4D4;
    }
  }

  .goods {
    background-image: url(../../../../assets/static/home/tuoyuan.png);
    background-repeat: no-repeat;
    background-size: 100% 100%;
    padding: 50px 15px 80px 15px;
    margin-top: -45px;

    .goods_list_card {
      display: flex;
      justify-content: space-between;
      font-size: 12px;
      font-weight: bold;
      text-align: center;

      > div {
        width: 74px;
        background-color: #fff;
        padding: 11px;
        border-radius: 8px;
        box-shadow: 0 0 10px #ccc;
      }

      img {
        height: 80px;
      }
    }

    .goods_title_flex {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin: 15px 0;

      img {
        width: 13px;
      }

      .card_title {
        display: flex;
        font-size: 15px;
        font-weight: bold;

        img {
          width: 4px;
        }

        > div {
          margin-left: 8px;
        }
      }
    }

    .goods_come {
      overflow: scroll;
      white-space: nowrap;
      height: 174.8px;

      > div {
        width: 140px;
        display: inline-block;
        margin-right: 15px;
        background-color: #fff;
        text-align: center;
        border-radius: 10px;
        overflow: hidden;

        img {
          width: 100%;
          height: 120px;
        }

        > div {
          font-size: 12px;
          font-weight: bold;
          //padding: 15px 0;
        }
      }
    }

    .goods_come::-webkit-scrollbar {
      display: none
    }
  }
}

/* tabbar */
.tabbar {
  width: 100%;
  position: fixed;
  display: flex;
  bottom: 0;
  left: 0;
  background-color: #fff;
  padding: 13px 0;
  justify-content: space-around;
  text-align: center;
  font-size: 10px;
  box-shadow: 0 -5px 10px #ccc;

  .thisList {
    color: #64C005;
  }
}

.goods-name > span {
  font-size: 12px;
  font-weight: bold;
}

.goods-name {
  height: 18.4px;
  padding: 15px 0;
}
</style>
